package com.chalk.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.chalk.dao.SysRegionDao;
import com.chalk.model.SysRegion;
import com.chalk.service.SysRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 省市区县行政区划地名表(SysRegion)表服务实现类
 *
 * @author maxiaoqiang
 * @since 2019-03-28 09:56:15
 */
@Service
public class SysRegionServiceImpl extends ServiceImpl<SysRegionDao, SysRegion> implements SysRegionService {

    @Autowired
    private SysRegionDao sysRegionDao;

    /*自定义接口*/

    /**
     * 根据主键批量(逻辑)删除
     *
     * @param ids
     * @return
     */
    @Override
    public int deleteBatchByPrimaryKey(String[] ids) {
        return sysRegionDao.deleteBatchByPrimaryKey(ids);
    }

    /**
     * 根据一组id，取回地区的名称
     *
     * @param ids
     * @return
     */
    @Override
    public Map<String, String> getNameByIds(String[] ids) {
        if (ids == null || ids.length == 0) {
            return null;
        }
        Map<String, String> namesMap = new HashMap<>();
        List<SysRegion> sysRegions = this.sysRegionDao.selectBatchIds(Arrays.asList(ids));
        if (sysRegions != null) {
            for (SysRegion sysRegion : sysRegions) {
                namesMap.put(sysRegion.getRegionId(), sysRegion.getRegionName());
            }
        }
        return namesMap;
    }

    ;
}